package com.sheng.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2016/4/4.
 */
public class ServiceConfigManager {
    private String mstrSharedPreferenceName = null;
    private SharedPreferences mshardPreferences = null;
    private static Context context = null;

    //用户账号相关
    private static final String STUDENT_USER_INFO = "com.student.STUDENT_USER_INFO";
    private static final String TEACHER_USER_INFO = "com.student.TEACHER_USER_INFO";

    private static class InnerConfigManager {
        private static final ServiceConfigManager instance = new ServiceConfigManager(context);
    }

    private ServiceConfigManager(Context context) {
        mstrSharedPreferenceName = new String(context.getPackageName() + "_preferences");
        mshardPreferences = context.getSharedPreferences(mstrSharedPreferenceName,
                Context.MODE_MULTI_PROCESS);
    }

    public static ServiceConfigManager getInstance(Context context) {
        ServiceConfigManager.context = context;
        ServiceConfigManager cm = InnerConfigManager.instance;
        return cm;
    }

    public void setStringValue(String key,
                               String value) {
        SharedPreferences.Editor editor = getSharedPreference().edit();
        editor.putString(key, value);
        editor.commit();
    }

    //登录服务器后返回的用户数据
    public void setLoginUserInfo(String data) {
        setStringValue(STUDENT_USER_INFO, data);
    }

    public String getLoginUserInfo() {
        return getStringValue(STUDENT_USER_INFO, "");
    }

    public void setLoginTeacherInfo(String data) {
        setStringValue(TEACHER_USER_INFO, data);
    }

    public String getLoginTeacherInfo() {
        return getStringValue(TEACHER_USER_INFO, "");
    }



    public int getIntValue(String key,
                           int defValue) {
        return getSharedPreference().getInt(key, defValue);
    }

    private SharedPreferences getSharedPreference() {
        return mshardPreferences;
    }


    public long getLongValue(String key,
                             long defValue) {
        return getSharedPreference().getLong(key, defValue);
    }



    public String getStringValue(String key,
                                 String defValue) {
        return getSharedPreference().getString(key, defValue);
    }




    public boolean getBooleanValue(String key,
                                   boolean defValue) {
        return getSharedPreference().getBoolean(key, defValue);
    }
}

